// pages/putInPoint/putInPoint/putInPoint.js
const app = getApp();
import Api from '../../../../utils/http';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchFlag: true,

    dataList: [{}, {}, {}, {}, {}],
  },
  //点击输入框
  searchClick: function () {
    this.setData({
      searchFlag: false
    })
  },
  //投放点详情
  toPointDetail: function (e) {
    var that = this
    var {
      dataList
    } = that.data
    let index = e.currentTarget.dataset.index
    var lid = dataList[index].id
    var longitude = dataList[index].longitude
    var latitude = dataList[index].latitude
    wx.navigateTo({
      url: `/pages/user/putInPoint/pointDetail/pointDetail?lid=${lid}&longitude=${longitude}&latitude=${latitude}`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.getPoinIndexDetail();
    that.getMyLocation();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  // 投放点列表展示信息
  getPoinIndexDetail: function () {
    var that = this;
    var param = {
      uid: app.globalData.uid,
      longitude: that.data.longitude,
      latitude: that.data.latitude,
    }
    console.log(param)
    Api.ajax("/app/Zlaunchpoint/pointlist", param).then(res => {
      console.log(res, "list")
      if (res.code == 200) {
        let arr = []
        let {
          often,
          list
        } = res[0]
        arr.push(often)
        list.forEach(item => {
          if (item.id != often.id) {
            arr.push(item)
          }
        })
        this.setData({
          dataList: arr
        });
      } else {

      }
    })
  },
  //获取当前位置信息
  getMyLocation: function () {
    var that = this;
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        console.log(res);
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,
          markers: [{
            iconPath: "",
            id: 0,
            latitude: res.latitude,
            longitude: res.longitude
          }],
        });
        // that.getMap();
      },
      fail: function (error) {
        console.error(error);
      },
      complete: function (res) {
        // console.log(res);
        wx.hideLoading();
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})